<template>
  <div class="app-container">
    <!-- 放置表单 -->
    <el-form
      ref="userForm"
      label-width="60px"
      :rules="rules"
      :model="userDetail"
    >
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userDetail.username" style="width: 300px" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input
          v-model="userDetail.password"
          disabled
          type="password"
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateSave">更新</el-button>
        <el-button>返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees'
export default {
  props: {
    userDetail: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      // 检验规则
      rules: {
        username: [
          { required: true, min: 2, max: 3, message: '请输入长度为2~20的字符', trigger: 'blur' }

        ]
      }
    }
  },
  methods: {
    updateSave () {
      this.$refs.userForm.validate(async isOk => {
        if (isOk) {
          // 调用接口
          await saveUserDetailById(this.userDetail)
          // 更新成功提示
          this.$message.success('更新成功')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
